package Text21;

import java.util.*;

public class Main {
    static int N = 500010;
    static int[] l = new int[N];
    static int[] r = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        for (int i = 0, sg = 0, sh = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'G') {
                l[i] = sh;
                sh = 0;
                sg++;
            } else if (s.charAt(i) == 'H') {
                l[i] = sg;
                sg = 0;
                sh++;
            }
        }
        for (int i = s.length() - 1, sg = 0, sh = 0; i >= 0; i--) {
            if (s.charAt(i) == 'G') {
                r[i] = sh;
                sh = 0;
                sg++;
            } else if (s.charAt(i) == 'H') {
                r[i] = sg;
                sg = 0;
                sh++;
            }
        }
        long res = 0;
        for (int i = 0; i < n; i++) {
            res += (long) l[i] * r[i] + Math.max(l[i] - 1, 0) + Math.max(r[i] - 1, 0);
        }
        System.out.println(res);
    }
}
